import http from '@/http';
import type {LoginParams, RegisterParams, ResponseData, UserInfo} from '@/types/interface';

const userApi = {
    // 登录
    login: (params: LoginParams): Promise<ResponseData<{ token: string; user: UserInfo }>> => {
        return http.post('/user/login', params);
    },

    // 注册
    register: (data: RegisterParams): Promise<ResponseData<{ userId: number }>> => {
        return http.post('/user/register', data);
    },

    // 获取用户信息
    getUserInfo: (userId: number): Promise<ResponseData<UserInfo>> => {
        return http.get(`/user/info?userId=${userId}`);
    },

    // 更新用户信息
    updateUser: (data: Partial<UserInfo>): Promise<ResponseData<boolean>> => {
        return http.put('/user/update', data);
    },

    // 上传头像
    uploadAvatar: (filePath: string): Promise<ResponseData<{ avatarUrl: string }>> => {
        return http.upload('/user/avatar', {
            filePath,
            name: 'avatar'
        });
    }
};

export default userApi;